package com.caption.api.handler.impl;

import com.caption.api.entity.FaceAuthCondition;
import com.caption.api.entity.FaceAuthResultDTO;
import com.caption.api.handler.base.AbstractHandler;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class FaceAuthHandler extends AbstractHandler {

    private FaceAuthCondition faceAuthCondition;

    public FaceAuthHandler(FaceAuthCondition faceAuthCondition){
        this.faceAuthCondition =faceAuthCondition;
    }

    @Override
    public FaceAuthResultDTO call() throws ExecutionException, InterruptedException, TimeoutException {
        Future<FaceAuthResultDTO> future= this.getApiSupport().getCommonExecutor().submit(()->{
          FaceAuthResultDTO faceAuthResultDTO = this.getApiSupport().getFaceAuthClient().call(faceAuthCondition).getData();
          return faceAuthResultDTO;
        });
        return future.get(120, TimeUnit.SECONDS);
    }
}
